package at.codebase.db.dao;

import static at.codebase.db.OfyService.ofy;

import java.util.ArrayList;
import java.util.Map;

import at.codebase.db.entities.EImage;
import at.codebase.db.entities.EUser;

/**
 * 
 * @author Lukas Pfeifhofer <lukas.pfeifhofer@devlabs.pro>
 *
 */
public class EImageDao {

	public static void addImage(final EImage imageEntity) {
		ofy().save().entity(imageEntity).now();
	}

	public static EImage getImageById(Long imageId) {
		if(imageId.longValue() <= 0)
			return null;
		return ofy().load().type(EImage.class).filter("imageId", imageId).first().get();
	}
	
	public static ArrayList<EImage> getImageByUploader(final Long userId) {
		return new ArrayList<EImage>(ofy().load().type(EImage.class).filter("uploader", EUser.key(userId)).list());
	}

	public static void removeImage(final EImage imageEntity) {	
		ofy().delete().type(EImage.class).id(imageEntity.getId().longValue());
	}
	
	public static void removeImageByIds(ArrayList<Long> ids) {
		ofy().delete().type(EImage.class).ids(ids);
	}

	public static Map<Long, EImage> getImagesByIds(ArrayList<Long> ids) {
		return ofy().load().type(EImage.class).ids(ids);
	}

}
